<?php
	$u_consultant = isset($_GET['consultant'])?$_GET['consultant']:'';
?>
<?php $this->load->view('header');?>
<div class="page-container">
    <?php $this->load->view('sidebar');?>
    <!-- BEGIN CONTENT -->
    <div class="page-content-wrapper">
        <div class="page-content">
            <?php $this->load->view('sale/_sub_nav');?>
            <div class="row">
                <div class="col-md-12">

                    <div class="table-toolbar">
                    <div class="form-inline">

                        <div class="pull-right">
                            <a href="<?php echo site_url('/teach/teacher_create');?>" class="btn blue" >
                             <i class="fa fa-plus"></i> 新建
                            </a>
                            <button id="teacher_search_btn" class="btn yellow">
                             <i class="fa fa-search"></i> 搜索
                            </button>
                        </div>
                    </div>
                </div>

                    <div class="row" style="display:none;" id="teacher_search_well">
                        <div class="col-md-1"></div>
                        <div class="col-md-10 well">
                            <form>
                                <table class="table">
                                    <tr><td colspan="6"><div class="well shallow-well">
                                        <span class="filter-link-list">
                                            按首字母来查询:
                                            <?php for($i=ord('a');$i<ord('z');$i++):?>
                                                 <a href="<?php echo site_url('/teach/teachers?letter='.chr($i));?>"><?php echo strtoupper(chr($i));?></a>
                                            <?php endfor;?>
                                        </span>
                                    </div></td>
                                    </tr>
                                    <tr>
                                        <td><label><?php echo lang('clue_student_name');?></label></td>
                                        <td><input type="text" name="student_name" class="form-control"></td>
                                        <td><label><?php echo lang('clue_student_no');?></label></td>
                                        <td><input type="text" name="student_no" class="form-control"></td>
                                        <td><label><?php echo lang('clue_phone');?></label></td>
                                        <td><input type="text" name="phone" class="form-control"></td>
                                    </tr>
                                    <tr>
                                        <td><label class="control-label"><?php echo lang('clue_last_contact_date');?></label></td>
                                        <td><div class="input-group input-large date-picker input-daterange" data-date="10/11/2012" data-date-format="mm/dd/yyyy">
                                            <input type="text" class="form-control" name="from">
                                            <span class="input-group-addon">
                                                 to
                                            </span>
                                            <input type="text" class="form-control" name="to">
                                        </div></td>
                                        <td><label class="control-label"><?php echo lang('clue_trade_wish');?></label></td>
                                        <td>
                                            <select class="form-control" name="trade_wish">
                                                 <?php foreach(config_item('comm.trade_wish') as $key=>$value):?>
                                                    <option value="<?php echo $key;?>"><?php echo $value;?></option>
                                                <?php endforeach;?>
                                            </select>
                                        </td>
                                        <td><label><?php echo lang('clue_consultant');?></label></td>
                                        <td>
                                            <select class="form-control" name="consultant">
                                                <option value="0">无</option>
                                                    <?php if (isset($consultants) && is_array($consultants) && count($consultants)) :?>
                                                        <?php foreach ($consultants as $consultant) :?>
                                                            <option value="<?php echo $consultant['id']; ?>" <?php echo set_select('consultant', $consultant['id'], $consultant['id']); ?>>
                                                                <?php echo(ucfirst($consultant['nickname'])); ?>
                                                            </option>
                                                        <?php endforeach; ?>
                                                    <?php endif;?>
                                            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td><label class="control-label"><?php echo lang('clue_school');?></label></td>
                                        <td><input type="text" class="form-control"></td>
                                        <td><label class="control-label"><?php echo lang('clue_grade');?></label></td>
                                        <td>
                                            <select class="form-control" name="grade">
                                                 <?php foreach(config_item('comm.grade') as $key=>$value):?>
                                                    <option value="<?php echo $key;?>"><?php echo $value;?></option>
                                                <?php endforeach;?>
                                            </select>
                                        </td>
                                        <td>
                                            <label class="control-label"><?php echo lang('clue_source');?></label>
                                        </td>
                                        <td>
                                            <select class="form-control" name="clue_source">
                                                 <?php foreach(config_item('comm.clue_source') as $key=>$value):?>
                                                    <option value="<?php echo $key;?>"><?php echo $value;?></option>
                                                <?php endforeach;?>
                                            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td><label class="control-label"><?php echo lang('clue_next_track_date');?></label></td>
                                        <td><input type="text" class="form-control"></td>
                                        <td><label class="control-label"><?php echo lang('from_big');?></label></td>
                                        <td>
                                            <select class="form-control" name="from_big">
                                                 <?php foreach(config_item('comm.from_big') as $key=>$value):?>
                                                    <option value="<?php echo $key;?>"><?php echo $value;?></option>
                                                <?php endforeach;?>
                                            </select>
                                        </td>
                                        <td>
                                            <label class="control-label"><?php echo lang('clue_stat');?></label>
                                        </td>
                                        <td>
                                            <select class="form-control" name="clue_stat">
                                                 <option value="0">未上门</option>
                                                 <option value="1">已上门</option>
                                            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="5"></td>
                                        <td><button class="btn btn-success" >查询</button> <button class="btn btn-default" type="submit">重置</button></td>
                                    </tr>

                                </table>
                            </form>
                        </div>
                        <div class="col-sm-1"></div>
                    </div>

                    <table class="table table-hover" id="teachers_table">
                        <thead>
                            <tr>
                                <th class="table-checkbox"><input type="checkbox" class="group-checkable" data-set="#teachers_table .checkboxes"></th>
                                <th><?php echo lang('teacher_name');?></th>
                                <th><?php echo lang('teacher_no');?></th>
                                <th><?php echo lang('teacher_phone');?></th>
                                <th><?php echo lang('teacher_entry_date');?></th>
                                <th><?php echo lang('teacher_type');?></th>
                                <th><?php echo lang('teacher_level');?></th>
                                <th><?php echo lang('teacher_info');?></th>
                                <th><?php echo lang('bf_actions');?></th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php if(isset($teachers)&&!empty($teachers)):?>
                            <?php foreach ($teachers as $key => $teacher):?>
                            <tr>
                                <td><input type="checkbox" class="checkboxes" value="<?php echo $teacher->teacher_id;?>"></td>
                                <td><a href="<?php echo site_url('/teach/teacher_view/'.$teacher->teacher_id);?>"><?php echo $teacher->teacher_name;?></a></td>
                                <td>T-<?php echo sprintf('%06d',$teacher->teacher_id);?></td>
                                <td><?php echo $teacher->phone;?></td>
                                <td><?php echo $teacher->entry_date;?></td>
                                <td><?php
                                $type = config_item('comm.teacher_type');
                                echo isset($type[($teacher->type)])?$type[($teacher->type)]:'';
                                ?></td>
                                <td><?php
                                $level = config_item('comm.teacher_level');
                                echo $level[($teacher->level)];
                                ?></td>
                                <td><?php echo $teacher->info;?></td>
                                <td>
                                    <a href="<?php echo site_url('/teach/teacher_edit/'.$teacher->teacher_id);?>" class="btn btn-xs btn-default">编辑</a>
                                    <?php if(has_permission('teach/teachers','teacher_delete')):?>
                                    <button data-pk="<?php echo $teacher->teacher_id;?>" class="btn btn-xs btn-danger teacher_delete_btn">删除</button>
                                    <?php endif;?>
                                </td>
                            </tr>
                            <?php endforeach;?>
                            <?php endif;?>
                        </tbody>
                    </table>

                    <div class="table-toolbar">
                            <?php if(has_permission('teach/teachers','teacher_delete')):?>
                            <a id="clue_delete_btn" class="btn red" >
                             <i class="fa fa-trash-o"></i> 删除
                            </a>
                            <?php endif;?>
                    </div>
	        </div>
        </div>
     </div>
</div>


    <?php $this->load->view('footer');?>

    <script type="text/javascript" src="assets/scripts/custom/clue.js"></script>

    <script>
        jQuery(document).ready(function() {
            App.init(); // initlayout and core plugins
            $(document).on('click','.teacher_delete_btn',function(){
                var id = $(this).attr('data-teacher');
                var tr = $(this).parents('tr');
                bootbox.confirm("确认删除该教师信息",function(result){
                    if(result) {
                        $.ajax({
                            url: 'teach/teacher_delete',
                            type: 'POST',
                            dataType: 'json',
                            data: {id: id}
                            })
                            .done(function(responseText) {
                               if(responseText.code==0) {
                                   tr.remove();
                                   toastr.success(responseText.msg);
                               } else {
                                   toastr.error(responseText.msg);
                               }
                            })
                            .fail(function() {
                            })
                            .always(function() {
                            });

                    }
                });
            });
        });
    </script>

    </body>
    <!-- END BODY -->
    </html>

	

